//
//  KeyChainManager.swift
//  SwiftProject
//
//  Created by qindong on 2021/3/4.
//

import UIKit

class KeyChainManager : NSObject {
    static let shared = KeyChainManager()
    // keyPrefix 设置前缀
    private let keychain = KeychainSwift(keyPrefix: BundleId)
    private let option = KeychainSwiftAccessOptions.accessibleWhenUnlockedThisDeviceOnly
    private let pinKey = "AppPin"
    
    var hasPin: Bool {
        if let _ = getPin() {
            return true
        } else {
            return false
        }
    }
    
    func getPin() -> String? {
        keychain.get(pinKey)
    }
    
    func setPin(value: String) {
        keychain.set(value, forKey: pinKey, withAccess: option)
    }
    
    func getValue(for key: String) -> String? {
        keychain.get(key)
    }
    
    func set(value: String, for key: String) {
        keychain.set(value, forKey: key, withAccess: option)
    }
}
